package top.wangjingxin.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import top.wangjingxin.base.Result;
import top.wangjingxin.service.DownloadService;

import java.io.BufferedWriter;
import java.io.File;
import java.math.BigInteger;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.stream.IntStream;

import static java.lang.Math.pow;

@RequestMapping("/api/v1/download")
@RestController
public class DownloadController {
    @Autowired
    DownloadService downloadService;

    @GetMapping("show")
    public Result show(String id) {
        return downloadService.show(id);
    }

    @PostMapping("upload")
    public Result upload(MultipartFile file) {
        return downloadService.upload(file);
    }

    @PostMapping("delete")
    public Result delete(String id) {
        return downloadService.delete(id);
    }

    @GetMapping("get")
    public ResponseEntity<byte[]> get(String id) {
        return downloadService.get(id);
    }
}
